home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / fullpath.arc / FULLPATH.C next >
Text File  |  1986-06-04  |  2KB  |  71 lines

  1. #include <stdio.h>
  2. #include <dos.h>
  3. #include <string.h>
  4.  
  5.  char *
  6. fullpath(s)
  7.  char *s;
  8. {
  9.  static char buf[FMSIZE*2];
  10.  extern char _SLASH;
  11.  char *p, *ld;
  12.  
  13.     if (s == NULL)
  14.         return(NULL);
  15.     if ((*s >= 'A' && *s <= 'Z' || *s >= 'a' && *s <= 'z') && s[1] == ':')
  16.     {
  17.         buf[0]= *s|' ';
  18.         s += 2;
  19.     } else
  20.         buf[0]=getdsk()+'a';
  21.     buf[1]=':';
  22.     p = &buf[2];
  23.     if (*s != _SLASH)
  24.     {
  25.         p[0]=_SLASH;
  26.         getcd(buf[0]-'a'+1, &p[1]);
  27.         p = &buf[strlen(buf)];
  28.         if (p[-1] != _SLASH)
  29.             *p++ = _SLASH;
  30.     }
  31.     strcpy(p, s);
  32.     for(p=buf ; *p ;)
  33.         if (*p >= 'A' && *p <= 'Z')
  34.             *p++ |= ' ';
  35.         else
  36.             if (*p == _SLASH)
  37.                 if (p[1] == _SLASH || p[1] == '\0' && p != &buf[2])
  38.                     strcpy(p, &p[1]);
  39.                 else
  40.                     if (p[1] == '.')
  41.                     {
  42.                         for(ld=p ; --ld > buf ;)
  43.                             if (*ld == _SLASH)
  44.                                 break;
  45.                         if (!(ld > buf))
  46.                             ld=p;
  47.                         if (p[2] == '.')
  48.                             if (p[3] == _SLASH)
  49.                             {
  50.                                 strcpy(ld, &p[3]);
  51.                                 p=ld;
  52.                             } else
  53.                                 if (p[3] == '\0')
  54.                                     (p=ld)[1]='\0';
  55.                                 else
  56.                                     p++;
  57.                         else
  58.                             if (p[2] == _SLASH)
  59.                                 strcpy(&p[1], &p[3]);
  60.                             else
  61.                                 if (p[2] == '\0')
  62.                                     p[1]='\0';
  63.                                 else
  64.                                     p++;
  65.                     } else
  66.                         p++;
  67.             else
  68.                 p++;
  69.     return(buf);
  70. }
  71.